package cn.kbs.controller;

import java.util.Locale;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.i18n.CookieLocaleResolver;
import org.springframework.web.servlet.i18n.SessionLocaleResolver;

@Controller
public class I18nController {
	
	
	
	@RequestMapping(value = "/helloz")
    public ModelAndView welcomez(HttpServletRequest request, HttpServletResponse response,User user) {
        ModelAndView modelAndView = new ModelAndView("welcome");
        ModelAndView modelAndView1 = new ModelAndView("../../jsp/indexz");
        
        if(user.getName().equals("adminz") && user.getPassword().equals("123456")){
        	
        	Locale locale = new Locale("zh", "CN");
        	request.getSession().setAttribute(SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME,locale);
        	return modelAndView;
        	
        }
        
        return modelAndView1 ;
        
    }
	@RequestMapping(value = "/helloe")
	public ModelAndView welcomee(HttpServletRequest request, HttpServletResponse response,User user) {
		ModelAndView modelAndView = new ModelAndView("welcome");
		ModelAndView modelAndView1 = new ModelAndView("../../jsp/indexe");
        
        if(user.getName().equals("admine") && user.getPassword().equals("123456")){
        	Locale locale = new Locale("en", "US");
        	request.getSession().setAttribute(SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME,locale);
            //(new CookieLocaleResolver()).setLocale (request, response, locale);
        	
        	return modelAndView;
        	
        }
        
        return modelAndView1 ;
	}
	@RequestMapping(value = "/helloj")
	public ModelAndView welcomej(HttpServletRequest request, HttpServletResponse response,User user) {
		ModelAndView modelAndView = new ModelAndView("welcome");
		ModelAndView modelAndView1 = new ModelAndView("../../jsp/indexj");
        
        if(user.getName().equals("adminj") && user.getPassword().equals("123456")){
        	
        	Locale locale = new Locale("ja", "JP");
        	request.getSession().setAttribute(SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME,locale);
        	return modelAndView;
        	
        }
        
        return modelAndView1 ;
	}
}
